/** *******************************************************************
 * FlexDatabaseManager
 * Copyright (c) 2008 Jonnie Spratley. All Rights Reserved.
 * @author  Jonnie Spratley
 * @contact jonniespratley@gmail.com
 * @internal
 ******************************************************************* */
package com.jonniespratley.flexdatabasemanager.vo
{
	import com.jonniespratley.flexdatabasemanager.view.assets.AssetManager;
	
	import mx.collections.ArrayCollection;
	import mx.utils.UIDUtil;
	
	[RemoteClass]
	[Bindable]
	public class DatabaseVO extends Object
	{
		
		public var aDBName:String;
		
		public var aDatabase:String;
		public var aType:String;
		public var aIcon:String;
		public var aData:String;
		public var aTables:ArrayCollection;
		public var aStatus:ArrayCollection;
		public var aSize:ArrayCollection;
		public var aIndexes:ArrayCollection;
		
		[Embed(source='/assets/images/Database.swf', symbol='Database')]
		public var aMedia:Class;
		public var databaseUUID:String;
		
		public function  DatabaseVO( obj:Object = null )
		{			
			if ( obj != null )
			{
				this.aDBName = obj['aDatabase'];
				this.aDatabase = obj['aDatabase'];
				this.aType = obj['aType'];
				this.aData = obj['aData'];
				this.aIcon = obj['aIcon'];
				
				//set the fields comming back as an Array 
				var tempArray:Array = obj['aTables'] as Array;
				
				//create a temp arraycollection so return to the aFields
				var tempAc:ArrayCollection = new ArrayCollection();
				
				//loop through every string in the fields array
				for ( var s:String in tempArray )
				{	
					//for each object add it to the temp collection
					tempAc.addItem( new TableVO( tempArray[s] ) );	
				}
				
				//set the array collection to the build one of value objects
				this.aTables = tempAc;
				
				
				/* ***********************************************
				 * Status parsing
				 *********************************************** */
				
				//set the fields comming back as an Array 
				var tempStatusArray:Array = obj['aStatus'] as Array;
				
				//create a temp arraycollection so return to the aFields
				var tempStatusAC:ArrayCollection = new ArrayCollection();
				
				//loop through every string in the fields array
				for ( var sString:String in tempStatusArray )
				{	
					//for each object add it to the temp collection
					tempStatusAC.addItem( new TableStatusVO( tempStatusArray[ sString ] ) );	
				}
				//set the array collection to the build one of value objects
				this.aStatus = tempStatusAC;
				
				
				/* ***********************************************
				 * Size parsing
				 *********************************************** */
				
				 //set the fields comming back as an Array 
				var tempSizeArray:Array = obj['aSize'] as Array;
				
				//create a temp arraycollection so return to the aFields
				var tempSizeAC:ArrayCollection = new ArrayCollection();
				
				//loop through every string in the fields array
				for ( var szString:String in tempSizeArray )
				{	
					//for each object add it to the temp collection
					tempSizeAC.addItem( new SizeVO( tempSizeArray[ szString ] ) );	
				}
				//set the array collection to the build one of value objects
				this.aSize = tempSizeAC;
			} 
		}
		
		public function get label():String
		{
			return aDatabase;
		}
		
		public function get children():Array
		{
			return aTables.toArray();
		}
		
		public function get status():ArrayCollection
		{
			return aStatus;
		}
		
		public function get size():ArrayCollection
		{
			return aSize;
		}
		
		public function get data():Object
		{
			return aType;
		}
		
		public function get type():String
		{
			return 'database';
		}
		
		public function get icon():Class
		{
			return AssetManager.voDatabaseIcon;
		}
		
		public function get info():String
		{
			return aDatabase;
		}
		
		public function get multimediaDataSource():Object
		{
			//multimediaDataSource=""
			//multimediaFunction=""
			var o:Object = new Object();
				o = 'assets/images/Database.swf';
			return o;
		}
		
		
		
		
		public function createUUID():String
		{
			return UIDUtil.createUID();
		}
	
	}
}